package com.iwhalecloud.bss.kite.cucc.service.attr.handler;

import com.iwhalecloud.bss.kite.common.constant.KeyConsts;
import com.iwhalecloud.bss.kite.common.util.KiteStringUtils;
import com.iwhalecloud.bss.kite.cucc.common.constant.LocalKeyConsts;
import com.iwhalecloud.bss.kite.cucc.service.pos.handler.CuccPosServiceUtils;
import com.iwhalecloud.bss.kite.cucc.service.util.ProdCateUtil;
import com.iwhalecloud.bss.kite.manager.api.IOperateSceneInstService;
import com.iwhalecloud.bss.kite.manager.api.IQuerySceneInstService;
import com.iwhalecloud.bss.kite.manager.inst.KiteAttr;
import com.iwhalecloud.bss.kite.manager.inst.KiteInst;
import com.iwhalecloud.bss.kite.manager.inst.KiteSceneInst;
import com.iwhalecloud.bss.kite.service.attr.AttrData;
import com.iwhalecloud.bss.kite.service.attr.handler.AbstractAttrHandler;
import org.springframework.beans.factory.annotation.Autowired;

public class AZClientAttrHandler extends AbstractAttrHandler {
    @Autowired
    private IQuerySceneInstService querySceneInstService;

    @Autowired
    IOperateSceneInstService operateSceneInstService;

    @Override
    public void after(KiteAttr attr, KiteInst inst, AttrData data) {
        // 吉林 光纤、以太网、数字电路 AZ端客户名称必填
        KiteSceneInst sceneInst = querySceneInstService.getSceneInst(data.getSceneInstId());
        String provinceCode = sceneInst.getProvinceNbr();
        String specId = inst.getSpecId();//产品实例id(prod_id)
        String cateId =  CuccPosServiceUtils.getCateId(data.getSceneInstId(),data.getCustId());
        if (LocalKeyConsts.PROVINCE_JILIN.equals(provinceCode)) {
            if (!specId.isEmpty()&&KiteStringUtils.equalsAny(cateId, ProdCateUtil.getProdIdByCodeForArr(ProdCateUtil.MV_CODE, ProdCateUtil.GXCZ_CODE, ProdCateUtil.YTW_CODE))) {
                attr.setIsNull(KeyConsts.IFTRUE_F);
            }
        }
        //河南、黑龙江 以太网/SDH/光纤 AZ端客户名称必填
        if (KiteStringUtils.equalsAny(provinceCode, LocalKeyConsts.PROVINCE_HENAN, LocalKeyConsts.PROVINCE_HEILONGJIANG)) {
            if(!specId.isEmpty()&&KiteStringUtils.equalsAny(cateId,ProdCateUtil.getProdIdByCodeForArr(ProdCateUtil.SDH_CODE, ProdCateUtil.GXCZ_CODE, ProdCateUtil.YTW_CODE))){
                attr.setIsNull(KeyConsts.IFTRUE_F);
            }
        }
        super.after(attr, inst, data);
    }
}
